package org.example.demo1.controller;

import org.example.demo1.common.PageData;
import org.example.demo1.common.ResponseData;
import org.example.demo1.domain.GoodsClassify;
import org.example.demo1.service.IGoodsClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods/classify")
public class GoodsClassifyController {

    @Autowired
    IGoodsClassifyService goodsClassifyService;

    @PostMapping
    public ResponseData<GoodsClassify> addClassify(@RequestBody GoodsClassify classify) {
        return goodsClassifyService.addClassify(classify);
    }

    @GetMapping("/{classifyId}")
    public ResponseData<GoodsClassify> getClassifyById(@PathVariable Integer classifyId) {
        return goodsClassifyService.getClassifyById(classifyId);
    }

    @GetMapping("/search")
    public ResponseData<GoodsClassify> searchClassify(@RequestParam String classifyName) {
        return goodsClassifyService.getClassifyByClassNameLike(classifyName);
    }

    @PutMapping
    public ResponseData<GoodsClassify> updateClassify(@RequestBody GoodsClassify classify) {
        return goodsClassifyService.updateClassify(classify);
    }

    @DeleteMapping("/{classifyId}")
    public ResponseData<GoodsClassify> deleteClassifyById(@PathVariable Integer classifyId) {
        return goodsClassifyService.deleteClassifyById(classifyId);
    }

    @GetMapping("/page")
    public ResponseData<PageData<GoodsClassify>> getClassifiesPage(@RequestParam int pageNum, @RequestParam int pageSize, @RequestParam(required = false) Integer classifyId) {
        return goodsClassifyService.getClassifiesPage(pageNum, pageSize, classifyId);
    }
}
